package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.http.glide.GlideApp;

/**
 * 图片网格适配器（每行3列）
 */
public class ImageGridAdapter extends AppAdapter<String> {

    public ImageGridAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView mImageView;

        private ItemViewHolder() {
            super(R.layout.image_grid_item);
            mImageView = findViewById(R.id.iv_image);
        }

        @Override
        public void onBindView(int position) {
            String imageUrl = getItem(position);
            
            // 使用 Glide 加载图片
            GlideApp.with(getContext())
                    .load(imageUrl)
                    .transform(new RoundedCorners(8))
                    .placeholder(R.drawable.test_2)
                    .error(R.drawable.test_2)
                    .into(mImageView);
        }
    }
}

